package com.cn.boot.student.controller.student.word;

import com.cn.boot.student.entity.WordEntity;
import com.cn.boot.student.service.student.IWordService;
import com.cn.boot.student.util.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 单词管理控制器
 */
@RestController
@Api(tags = "单词管理")
@RequestMapping("/admin/word")
public class WordController {
    @Autowired
    private IWordService iWordService;
    /**
     * 查询单词（单词列表）
     * 条件查询
     */
    @PostMapping("/findAll")
//    @PreAuthorize("hasAuthority('sys:word:read')")
    @ApiOperation(value = "单词列表")
    public CommonResult findAll(WordEntity wordEntity){
        return iWordService.findAll(wordEntity);
    }
    /**
     * 我的收藏
     */
    @PostMapping("/myCollection")
//    @PreAuthorize("hasAuthority('sys:word:read')")
    @ApiOperation(value = "我的单词列表")
    public CommonResult myCollection(WordEntity wordEntity){
        return iWordService.myCollection(wordEntity);
    }
    /**
     * 添加单词
     */
    @PostMapping("/add")
//    @PreAuthorize("hasAuthority('sys:word:add')")
    @ApiOperation(value = "添加单词")
    public CommonResult add(WordEntity wordEntity){
        return iWordService.add(wordEntity);
    }


    /**
     * 更新单词数据
     */
    @PostMapping("/update")
//    @PreAuthorize("hasAuthority('sys:word:update')")
    @ApiOperation(value = "添加单词")
    public CommonResult update(WordEntity wordEntity){
        return iWordService.update(wordEntity);
    }

    /**
     * 删除单词
     */
    @DeleteMapping("/del")
//    @PreAuthorize("hasAuthority('sys:word:del')")
    @ApiOperation(value = "删除单词")
    public CommonResult del(@RequestParam Integer id){
        return iWordService.del(id);
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/dels")
//    @PreAuthorize("hasAuthority('sys:word:del')")
    @ApiOperation(value = "删除单词")
    public CommonResult dels(@RequestParam  List<Integer> ids){
        return iWordService.dels(ids);
    }
    /**
     * 根据id查询单词
     */
    @PostMapping("/findById")
//    @PreAuthorize("hasAuthority('sys:word:read')")
    @ApiOperation(value = "根据id查询单词")
    public CommonResult findById(@RequestParam Integer id){
        return iWordService.findById(id);
    }

    /**
     * 单词收藏
     */
    @PostMapping("/collectWord")
//    @PreAuthorize("hasAuthority('sys:word:add')")
    @ApiOperation(value = "单词收藏")
    public CommonResult collectWord(WordEntity wordEntity){
        return iWordService.collectWord(wordEntity);
    }
    /**
     * 单词点赞
     */
    @PostMapping("/likeWord")
//    @PreAuthorize("hasAuthority('sys:word:add')")
    @ApiOperation(value = "单词点赞")
    public CommonResult likeWord(WordEntity wordEntity){
        return iWordService.likeWord(wordEntity);
    }
}
